﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using MM.Model;
using MM.Common;

namespace MM.DBUtility
{
    public class BLSqlDataCharge
    {
        /// <summary>
        /// 得到屏蔽关键字
        /// </summary>
        /// <param name="strColumn"></param>
        /// <returns></returns>
        public static ArrayList GetMaskInfo(string strColumn, string strChannelNO)
        {
            ArrayList argList = new ArrayList();
            DataSet ds = DbHelperSql.Query(string.Format("SELECT {0} FROM T_Mask WHERE {0}<>'' AND ChannelNO='{1}'", strColumn, strChannelNO));
            if (ds != null && ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow row in ds.Tables[0].Rows)
                    {
                        argList.Add(row[strColumn] == null ? "" : row[strColumn].ToString());
                    }
                }
            }
            return argList;
        }
        /// <summary>
        /// 得到二次确认关键字
        /// </summary>
        /// <param name="strColumn"></param>
        /// <param name="strChannelNO"></param>
        /// <returns></returns>
        public static ArrayList GetDoubleInfo(string strColumn, string strChannelNO)
        {
            ArrayList argList = new ArrayList();
            DataSet ds = DbHelperSql.Query(string.Format("SELECT {0} FROM T_Double WHERE {0}<>'' AND ChannelNO='{1}'", strColumn, strChannelNO));
            if (ds != null && ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow row in ds.Tables[0].Rows)
                    {
                        argList.Add(row[strColumn] == null ? "" : row[strColumn].ToString());
                    }
                }
            }
            return argList;
        }
        /// <summary>
        /// 设定SMI卡信息
        /// </summary>
        /// <param name="strImsi"></param>
        public static void SetSIMinfo(string strConn, string strArea, string strOp, string strId, string strImsi, string ChannelNO, int SentNum)
        {
            DbHelperSql.ExecuteNonQuerySP(strConn, "SP_CreateSIM",
                   new SqlParameter("@Imsi", strImsi),
                   new SqlParameter("@AreaNO", strArea),
                   new SqlParameter("@ONO", strOp),
                   new SqlParameter("@CNO", strId),
                   new SqlParameter("@ChannelNO", ChannelNO),
                   new SqlParameter("@SentNum", SentNum));
        }
        /// <summary>
        /// 设定SMI卡信息,+手机返回信息，以便查处多次扣费原因
        /// </summary>
        /// <param name="strArea"></param>
        /// <param name="strOp"></param>
        /// <param name="strId"></param>
        /// <param name="strImsi"></param>
        /// <param name="ChannelNO"></param>
        /// <param name="Result"></param>
        //public static void SetSIMinfo(string strArea, string strOp, string strId, string strImsi, string ChannelNO, string Result)
        //{
        //    ArrayList alist = new ArrayList();
        //    alist.Add(string.Format("INSERT INTO T_SIM(CNO,IMSI,AreaNO,ONO,ChannelNO) VALUES('{0}','{1}','{2}','{3}','{4}')", strId, strImsi, strArea, strOp, ChannelNO));
        //    alist.Add(string.Format("INSERT INTO T_ReturnTemp(IMSI,Result) VALUES('{0}','{1}')", strImsi, DESEncrypt.Encrypt(Result)));
        //    DbHelperSql.ExecuteSqlTran(alist);
        //}
        /// <summary>
        /// 所有SMI卡请求信息
        /// </summary>
        /// <param name="strImsi"></param>
        public static void SetSIMallinfo(string strConn, string strArea, string strOp, string strId, string strImsi, string ChannelNO)
        {
            DbHelperSql.ExecuteNonQuerySP(strConn, "SP_CreateSIMall",
               new SqlParameter("@Imsi", strImsi),
               new SqlParameter("@AreaNO", strArea),
               new SqlParameter("@ONO", strOp),
               new SqlParameter("@CNO", strId));
        }
        /// <summary>
        /// 3.0所有SMI卡请求信息
        /// </summary>
        /// <param name="strArea"></param>
        /// <param name="strOp"></param>
        /// <param name="strId"></param>
        /// <param name="strImsi"></param>
        /// <param name="ChannelNO"></param>
        public static void SetSIMallinfo(string strArea, string strOp, string strId, string strImsi, string ChannelNO, string strPhoneid, string strImei, string strDevice)
        {
            try
            {
                DbHelperSql.ExecuteSql(string.Format("INSERT INTO T_SIMall(CNO,IMSI,AreaNO,ONO,ChannelNO,PhoneId,Imei,Device) VALUES('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')", strId, strImsi, strArea, strOp, ChannelNO, strPhoneid, strImei, strDevice));
            }
            catch { }
        }
        /// <summary>
        /// 取得中文完整位数字符串
        /// </summary>
        /// <param name="strValue"></param>
        /// <param name="intLength"></param>
        /// <returns></returns>
        public static string GetGB2132FullString(string strValue, int intLength)
        {
            StringBuilder sb = new StringBuilder();
            int intTemp = strValue.Length * 3;
            if (intTemp <= intLength)
            {
                sb.Append(strValue);
                for (int i = 0; i < intLength - intTemp; i++)
                {
                    sb.Append("\0");
                }
            }
            else
            {
                sb.Append(strValue.Substring(0, intLength));
            }
            return sb.ToString();
        }
        /// <summary>
        /// 取得完整位数字符串
        /// </summary>
        /// <param name="strValue"></param>
        /// <param name="intLength"></param>
        /// <returns></returns>
        public static string GetFullString(string strValue, int intLength)
        {
            StringBuilder sb = new StringBuilder();
            int intTemp = strValue.Length;
            if (intTemp <= intLength)
            {
                sb.Append(strValue);
                for (int i = 0; i < intLength - intTemp; i++)
                {
                    sb.Append("\0");
                }
            }
            else
            {
                sb.Append(strValue.Substring(0, intLength));
            }
            return sb.ToString();
        }
        /// <summary>
        /// 整数转换ASCII(16进制),返回string
        /// </summary>
        /// <param name="intValue"></param>
        /// <returns></returns>
        public static string GetASCIIbyInt(int intValue, int intLength)
        {
            byte[] byResult = new byte[intLength];
            byte[] byArr = BitConverter.GetBytes(intValue);
            for (int i = 0; i < intLength; i++)
            {
                byResult[i] = byArr[i];
            }
            return System.Text.Encoding.ASCII.GetString(byResult);
        }

    }
}
